package com.sunrise.gateway.web.servlet;

import com.sunrise.gateway.commons.CommonUtils;
import com.dap.utils.SpringUtils;
import com.sunrise.gateway.web.core.ParamMapGetRequestEngine;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class NotifyAlipayServlet extends ServletBase {
    private ParamMapGetRequestEngine engine;

    @Override
    public void init() throws ServletException {
        engine = SpringUtils.getBean(ParamMapGetRequestEngine.class);
        super.init();
    }

    @Override
    protected void doMyPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        execute(req, resp);
    }


    private void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String code = "success";
        try {
            engine.execute(req, null, "AlipayCallback");
        } catch (Exception e) {
            LOGGER.info("", e);
            code = "error";
        }

        CommonUtils.writeStrIntoResponse(code, resp);
    }

}
